﻿using System.Linq;
using System.Threading.Tasks;
using cfg.card;
using kemocard.Scripts.Buff;
using kemocard.Scripts.Common;
using kemocard.Scripts.Module.Battle;
using kemocard.Scripts.MVC;

namespace kemocard.Scripts.Card.Scripts;

public class C8 : BaseHealCard;

public class C11 : BaseHealCard;

public class C12 : BaseHealCard;

public class C31 : BaseHealCard;

public class C50 : BaseHealCard;

public class FesZellerSupport : BaseHealCard;

public class SlimeEarthSupport : BaseHealCard;

public class LizEarthSupport : BaseHealCard;

public class SciSantosS : BaseHealCard;

public class SsRainsS : BaseHealCard;

public class FortisCarterS : BaseCardScript
{
    public override async Task UseCard(BaseBattleCard parent)
    {
        parent.User.Power += 30;
        if (Mod == null)
        {
            return;
        }

        HealStruct heal = new()
        {
            Value = (int)parent.CalculateRealTimeValue(1, [Tag.HEAL]),
            Role = parent.User.Role,
            Attribute = parent.Attribute,
            Target = parent.Target,
            User = parent.User,
        };
        await Mod.DoHeal(heal);
    }
}

public class KnightCollinS : BaseHealCard;

public class FortisZellerS : BaseHealCard
{
    protected override void AfterHeal(BaseBattleCard parent)
    {
        if (parent.Heal < 10000) return;
        var buff = StaticUtil.NewBuffOrNullById("FORTIS_ZELLER_S", parent.User);
        if (buff == null || Mod?.Teammates == null) return;
        foreach (var character in Mod.Teammates)
        {
            var t = (BaseBuff)buff.Clone();
            character.AddBuff(t);
        }
    }
}

public class MetalZcS : BaseHealCard
{
    protected override void AfterHeal(BaseBattleCard parent)
    {
        var buff = StaticUtil.NewBuffOrNullById("METAL_ZC_S", parent.User);
        if (buff == null || Mod?.Teammates == null) return;
        foreach (var character in Mod.Teammates)
        {
            var t = (BaseBuff)buff.Clone();
            character.AddBuff(t);
        }
    }
}

public class SciRainsS : BaseHealCard
{
    protected override void AfterHeal(BaseBattleCard parent)
    {
        var buff = StaticUtil.NewBuffOrNullById("SCI_RAINS_S", parent.User);
        if (buff == null || Mod?.Teammates == null) return;
        buff.TempValue = parent.CalculateRealTimeValue(1, [Tag.HEAL, Tag.WATER, Tag.AT]);
        foreach (var character in Mod.Teammates)
        {
            var t = (BaseBuff)buff.Clone();
            character.AddBuff(t);
        }
    }
}

public class WaiterCollinS : BaseHealCard;

public class SwordRainsS : BaseHealCard
{
    public override void UpdateRealTimeValue(BaseBattleCard parent, ref float result)
    {
        if (parent.User.TempUsedCard.Count > 2)
        {
            result = (int)parent.CalculateRealTimeValue(parent.Value, 0, 0, 1.2f);
        }
    }
}

public class OnsenTyphoonS : BaseHealCard
{
    protected override void AfterHeal(BaseBattleCard parent)
    {
        if (parent.User.Heal < 10000 || Mod?.Teammates == null) return;
        var buff = StaticUtil.NewBuffOrNullById("ONSEN_TYPHOON_S", parent.User);
        if (buff == null) return;
        foreach (var battleCharacter in Mod.Teammates.Where(c => !c.IsDead))
        {
            var t = (BaseBuff)buff.Clone();
            battleCharacter.AddBuff(t);
        }
    }
}

public class OnsenRainsS : BaseHealCard
{
    protected override void AfterHeal(BaseBattleCard parent)
    {
        parent.Target.ForEach(pawn =>
        {
            if (pawn is BattleCharacter bc)
            {
                bc.Power += 20;
            }
        });
    }
}